# -*- coding:utf-8 -*-

import os
from PIL import Image


def main():
    filepath = os.path.join(r'D:\python_project\ba4988\data\FONT.ROM')
    f = open(filepath, 'rb')
    content = f.read()
    f.close()
    save_bmp = False
    s='释义例句例证习语复合派生用法同反'
    # s='事'
    for ch in s:
        hz = ch.encode('GB2312')
        print(f'{hz[0]:02X}{hz[1]:02X}')
        start = (hz[0]-0xB0)*32*94+(hz[1]-0xA0-1)*32
        if save_bmp:
            datas = []
            for data in content[start:start+32]:
                datas.append(255-data)
            filename = f'{ch}.bmp'
            image = Image.frombytes('1', (16,16), bytes(datas))
            image.save(filename)
        buff = ''
        for i in range(32):
            buff += '{:08b}'.format(content[start+i])
        for y in range(16):
            for x in range(16):
                print(buff[16*y+x].replace('0', '  ').replace('1', '██'), end='')
            print('')


if __name__ == '__main__':
    main()